package com.zhangfb95.crosschain.console.command;

import com.zhangfb95.crosschain.console.enums.CommandEnum;
import com.zhangfb95.crosschain.sdk.CrossChainClient;
import com.zhangfb95.crosschain.sdk.infra.model.service.dto.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zhangfubing
 * @since 2023/12/21
 */
@Component
public class LogoutCommand implements Command {

    @Autowired
    private CrossChainClient crossChainClient;

    @Override
    public CommandEnum command() {
        return CommandEnum.LOGOUT;
    }

    @Override
    public boolean handle(String[] args) {
        if (isHelp(args)) {
            System.out.println("Usage: logout");
            return false;
        }

        UserInfo currentUserInfo = crossChainClient.logout();
        System.out.println("Result: success");
        if (currentUserInfo != null) {
            System.out.println("username: " + currentUserInfo.getUsername());
        }
        return false;
    }
}
